package com.power.sifa.approve.dao;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.query.Param;
import com.power.sifa.approve.model.Apl_dossier;

import javax.transaction.Transactional;
import java.io.Serializable;
import java.util.List;

/**
 * 电子卷宗 持久层(hibernate)
 */

public interface Apl_dossierDao extends JpaRepository<Apl_dossier, Serializable>, JpaSpecificationExecutor<Apl_dossier>, Repository<Apl_dossier, Serializable>, Apl_dossierDaoCustom<Apl_dossier, Serializable> {

   @Modifying
   @Transactional
   @Query("delete  from Apl_dossier s where  s.id in (:ids) ")
   void removeByIds(@Param("ids") List<Integer> ids);

   @Query("from Apl_dossier s where  s.applyid = :applyid")
   List<Apl_dossier> getByApplyid(@Param("applyid") String applyid);

   /**
    * 根据applyid和节点类型查询列表
    * @param applyid
    * @param type
    * @return
    */
   @Query("from Apl_dossier s where  s.applyid = :applyid and s.type = :type")
   List<Apl_dossier> getByApplyid(@Param("applyid") String applyid, @Param("type") Integer type);

   @Modifying
   @Transactional
   @Query("delete  from Apl_dossier s where  s.applyid = :applyid")
   void removeByApplyid(@Param("applyid") String applyid);

   @Modifying
   @Transactional
   @Query("delete  from Apl_dossier s where  s.parentid = :parentid")
   void removeByParentid(@Param("parentid") String parentid);

   @Query("select max(s.sort)  from Apl_dossier s where  s.parentid = :parentid")
   Integer queryMaxSotrByParentid(@Param("parentid") String parentid);

}
